package com.wkbb.basic.utils;

/**
 * @author dengjingyuan
 * @date 2019-07-04 10:32
 */
public class YouTuSign {
	/**
	 * 算法标识
	 */
	private static final String HMAC_SHA1 = "HmacSHA1";
	/**
	 * Authorization方法
	 * @param userQq 开发者创建应用时的QQ号
	 * @param AppId 开发者创建应用后的AppID
	 * @param SecretId 开发者创建应用后的SecretID
	 * @param SecretKey 开发者创建应用后的SecretKey
	 * @return sign
	 * @throws Exception
	 */
	public static String getSign(String userQq,String AppId,String SecretId,String SecretKey) throws Exception{
		long tnowTimes = System.currentTimeMillis()/1000;
		long enowTimes = tnowTimes+2592000;
		String rRandomNum = HmacSha1.genRandomNum(10);
		String param = "u=" + userQq + "&a=" + AppId + "&k=" + SecretId + "&e="
				+ enowTimes + "&t=" + tnowTimes + "&r=" + rRandomNum + "&f=";
		byte [] hmacSign = HmacSha1.getSignature(param, SecretKey);
		byte[] all = new byte[hmacSign.length+param.getBytes().length];
		System.arraycopy(hmacSign, 0, all, 0, hmacSign.length);
		System.arraycopy(param.getBytes(), 0, all, hmacSign.length, param.getBytes().length);
		String sign = base64Url.encode(all);
		return sign;
	}
}
